<template>
  <el-dialog
          :close-on-click-modal="false"
          :show-close="false"
          :title="form.id ? '重置密码':''"
          :visible.sync="isChange"
  >
    <el-form
            :rules="rules"
            ref="ruleForm"
            :model="form"
            label-width="120px"
            size="small"
            class="form-box"
    >
      <el-form-item label="密码" prop="password">
        <el-input type="text" v-model="form.password" placeholder="请输入您的密码"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="$emit('closeDialog')" size="small">取消</el-button>
      <el-button @click="submitFormPass('ruleForm')" type="primary" size="small">确定</el-button>
    </span>
  </el-dialog>
</template>

<script lang="ts">
  import {Component, Vue, Prop, Provide} from "vue-property-decorator";
  import staffManag from "@/api/staffManag";

  @Component({
    components: {}
  })
  export default class typeEditDialog extends Vue {
    // 属性或参数中使用 ！：表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
    check: boolean = true//防重复提交
    @Prop(Number) id!: number
    @Prop(Boolean) isChange!: boolean;
    @Prop(Object) form!: {
      id: string,
      password: string,
    };
    @Provide() rules: any = {
      password: [{required: true, message: "请输入密码", trigger: "blur"}],
    };

    // 提交
    submitFormPass(formName: any) {
      (this.$refs[formName] as any).validate((valid: boolean) => {
        if (valid) {
          if (this.check) {
            let _this = this
            _this.check = false
            staffManag.employeePsss(_this.form)
                    .then((res: any) => {
                      if (res.data.code == 200) {
                        _this.$message({
                          message: res.data.msg,
                          type: "success"
                        });
                        _this.$emit("closeDialog");
                        _this.$emit("loadData");
                        setTimeout(function () {
                          _this.check = true
                        }, 3000)
                      } else {
                        _this.$message({
                          message: res.data.msg,
                          type: "error"
                        });
                        _this.check = true
                      }
                    });
          }
        }
      })
    }

    created() {
    }
  }
</script>

<style lang="scss" scoped>
  .form-box {
    .el-input,
    .el-select {
      width: 200px !important;
    }
  }
</style>
